<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        canvas{border: 1px solid red;}
    </style>
</head>
<body>
<canvas id="box" width="500" height="500"></canvas>
<script>
    var box=document.getElementById("box");
    var pen=box.getContext("2d");
    var ele=pen.createLinearGradient(20,20,400,400);
    ele.addColorStop(0,"red");
    ele.addColorStop(0.5,"green");
    ele.addColorStop(1,"blue");
    pen.beginPath();
    pen.moveTo(20,20);
    pen.lineTo(400,400);
    pen.strokeStyle=ele;
    pen.closePath();
    pen.stroke();
    var ra=pen.createLinearGradient(400,400,10,400,400,400);










</script>
</body>
</html>